package com.minyue.sqlsession;

import com.minyue.config.XMLConfigurationBuilder;
import com.minyue.pojo.Configuration;
import org.dom4j.DocumentException;

import java.beans.PropertyVetoException;
import java.io.InputStream;

/**
 * @author ：minyue
 * @date ：Created in 2021/7/22 10:48 下午
 * @description：
 */
public class SqlSessionFactotyBuilder {

    private Configuration configuration;

    public SqlSessionFactotyBuilder() {
        configuration = new Configuration();
    }

    public SqlSessionFactory builder(InputStream inputStream) throws PropertyVetoException, DocumentException {
        //1.解析配置文件，封装Configuration
        XMLConfigurationBuilder xmlConfigurationBuilder = new XMLConfigurationBuilder(configuration);
        xmlConfigurationBuilder.parseConfiguration(inputStream);
        //2、创建sqlSessionFactory
        return new DefaultSqlSessionFactory(configuration);
    }
}
